package br.com.news.util;

import java.util.List;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

public class DialogUtil {

	private DialogUtil() {}
	
	public static void showDialog(Context context, String message,
			List<ButtonDialog> buttons) {
		AlertDialog dialog = new AlertDialog.Builder(context).create();
		dialog.setMessage(message);
		for (ButtonDialog buttonDialog : buttons) {
			dialog.setButton(DialogInterface.BUTTON_NEUTRAL,
					buttonDialog.getTitle(), buttonDialog.getClickListener());
		}
		dialog.show();
	}

	public static void showDialog(Context context, String message,
			ButtonDialog button) {
		AlertDialog dialog = new AlertDialog.Builder(context).create();
		dialog.setMessage(message);
		dialog.setButton(DialogInterface.BUTTON_NEUTRAL,
				button.getTitle(), button.getClickListener());

		dialog.show();
	}

	public static class ButtonDialog {

		private String title;
		private OnClickListener clickListener;

		private ButtonDialog(String title, OnClickListener clickListener) {
			this.title = title;
			this.clickListener = clickListener;
		}

		public String getTitle() {
			return title;
		}

		public void setTitle(String title) {
			this.title = title;
		}

		public OnClickListener getClickListener() {
			if (clickListener == null) {
				clickListener = new OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
					}
				};
			}
			return clickListener;
		}

		public void setClickListener(OnClickListener clickListener) {
			this.clickListener = clickListener;
		}

		public static ButtonDialog getButtonOk(Context cxt) {
			return new ButtonDialog(cxt.getString(android.R.string.ok), null);
		}

	}
}
